package com.example.androidwebpj.service;

import android.util.Log;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class SimpleNanoService extends NanoHTTPD {

    private String TAG = "SimpleNanoService";

    public SimpleNanoService(int port) {
        super(port);
    }


    @Override
    public Response serve(IHTTPSession session) {
        Log.d(TAG, "serve: ......");
        String msg = null;
        InputStream inputStream = null;
        try {
            msg = "<!DOCTYPE html><html><body> <p>Hello NanoHTTPD!!!</p> </body></html>\n";
            inputStream = new ByteArrayInputStream(msg.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "serve: error:"+e.getMessage());
        }
        return new Response(Response.Status.OK,NanoHTTPD.MIME_HTML,inputStream,msg.getBytes().length);
    }

}
